const { ccclass, property, executeInEditMode } = cc._decorator;

@ccclass
@executeInEditMode
export default class CircleGradient extends cc.Component {

    @property
    _color: cc.Color = cc.Color.WHITE;
    @property
    set color(color: cc.Color) {
        this._color = color;
        this.updateProperties();
    }
    get color() { return this._color };

    @property
    _oPoint: cc.Vec2 = cc.v2(.5, .5);
    @property
    set oPoint(val: cc.Vec2) {
        this._oPoint.set(val);
        this.updateProperties();
    }
    get oPoint() { return this._oPoint };

    @property
    _radius: cc.Vec2 = cc.v2(.3, .5);
    @property
    set radius(val: cc.Vec2) {
        this._radius.set(val);
        this.updateProperties();
    }
    get radius() { return this._radius };

    _mat: cc.Material = null;

    onLoad() {
        this._mat = this.node.getComponent(cc.Sprite).getMaterial(0);
        this.updateProperties();
    }

    start() {

    }

    updateProperties() {
        if (!this._mat) this._mat = this.node.getComponent(cc.Sprite).getMaterial(0);
        this._mat.setProperty("colorAmbient", this._color);
        this._mat.setProperty("oPoint", this._oPoint);
        this._mat.setProperty("radius", this._radius);
    }
}
